package proj1.dao;

import java.sql.SQLException;
import java.util.EnumSet;
import java.util.Set;
import java.util.TreeSet;

import proj1.constants.C.COMPARATOR;
import proj1.dao.Radiator.SIZE;
import proj1.oracle.OracleDB;
import proj1.util.Logger;

// A vendor is basically just a collection
// of radiators. The vendorKey is the suffix
// to the table name (eg: RDIMARS the vendorKey would be ARS)
public enum Vendor { 
	ARS, BEH, DAN, MOD;
	
	private static Logger log = Logger.getLogger(Vendor.class);
	
	// Get a list of parts by vendor
	public Set<Radiator> getRadiators(){
		OracleDB conn = OracleDB.getInstance();
		String query = "select * from RDIM" + this.name();
		Set<Radiator> result = new TreeSet<Radiator>(COMPARATOR.RADIATOR);
		// For each item in the results, create a new Radiator object and add it to the result set
		try {
			// Execute the query via the OracleDB connection
			result = Radiator.radiatorsFromResults(conn.executeQuery(query));
		} catch (SQLException e) {
			log.error("A SQL Exception occurred during Make fetch.", e);
		}
		return result;
	}
	public Set<Radiator> getRadiators(SIZE size){
		OracleDB conn = OracleDB.getInstance();	
		Set<Radiator> radiators=  new TreeSet<Radiator>(COMPARATOR.RADIATOR);
			// Build the query and insert results into the radiators set
			String query = "select rad.* from radcrx crx" 
						+ " join RDIM" + this.name() + " rad"
						+ " on crx." + this.name() + size.colNum + " = rad.p_number ";
			
			try {
				// Execute the query via the OracleDB connection
				radiators = Radiator.radiatorsFromResults(conn.executeQuery(query));

			} catch (SQLException e) {
				log.error("A SQL Exception occurred during radiator by model fetch.", e);
			}
		return radiators;
	}	
	public static EnumSet<Vendor> getVendors(){
		return EnumSet.of(ARS, BEH, DAN, MOD);
	}
}
